//统一管理用户相关的接口
import request from "@/utils/request";
import type { loginForm,mockLoginForm } from "./type" 
//统一管理接口
enum API {
    LOGIN_URL = "/auth/login",
    LOGOUT_URL = "/auth/logout",
    UserInfo_URL = "/itp/api/menu/find/currentUser",  
    UserPage_URL = "/itp/api/user",
    UserRole_URL = "/itp/api/userRole",
    UserMenu_URL = "/itp/api/userMenu",
    Pref_URL = "/itp/api/pref/combination",
    Mock_URL = "/auth",
}
//暴露请求函数
//登录接口方法
export const reqLogin = (data:loginForm) => request.post(API.LOGIN_URL,data);
// 退出登录
export const reqLogout = () => request.post(API.LOGOUT_URL);
//获取用户及权限信息
export const reqUserInfo = () => request.get(`${API.UserInfo_URL}?dictMenuPlan=1&isShow=0`);
//模拟登录
export const mockLogin = (data:mockLoginForm) => request.post(`${API.Mock_URL}/mockLogin`,data); 
//切换模拟登录
export const switchLogin = (data:mockLoginForm) => request.post(`${API.Mock_URL}/mockSwitch`,data); 

export default {
    getUserList: (current: number, size: number, data: any) => request.post(`${API.UserPage_URL}/page?current=${current}&size=${size}`, data),
    getUserDetail: (id: number) => request.get(`${API.UserPage_URL}/contact/id?id=${id}`),
    userDelete: (id: number) => request.delete(`${API.UserPage_URL}?id=${id}`),
    // userAdd: (param: any) => request.post(`${API.UserPage_URL}`,param),
    userAdd: (param: any) => request.post(`${API.UserPage_URL}/contact`,param),
    userUpdate: (param: any) => request.put(`${API.UserPage_URL}`,param),
    updatePsd: (param: any) => request.put(`${API.UserPage_URL}/password`,param),
    userSelect: (param: string) => request.get(`${API.UserPage_URL}/select?searchKey=${param}`),
    
    getUserRole: (param: any) => request.get(`${API.UserRole_URL}/bind/role${param}`),
    getRoleUser: (param: any) => request.get(`${API.UserRole_URL}/bind/user${param}`),
    getUserUnbindRole: (param: any) => request.get(`${API.UserRole_URL}/unbind/role${param}`),
    getRoleUnbindUser: (param: any) => request.get(`${API.UserRole_URL}/unbind/user${param}`),
    deleteUserRole: (id: number) => request.delete(`${API.UserRole_URL}?id=${id}`),
    addBatchUserRole: (param: any) => request.post(`${API.UserRole_URL}/batch`,param),
    updateUserRole: (param: any) => request.put(`${API.UserRole_URL}`,param),

    getUserMenu: (param: any) => request.get(`${API.UserMenu_URL}/bind${param}`),
    bindUserMenu: (param: any) => request.put(`${API.UserMenu_URL}/bind`,param),
    updateBatchUserMenu: (param: any) => request.put(`${API.UserMenu_URL}/batch`,param),

    getThemePref: (param: any) => request.post(`${API.Pref_URL}/all/with/detail`, param),
    saveThemePref: (param: any) => request.post(`${API.Pref_URL}/save/update/all/with/detail`, param),
    getSelectUserList: (searchKey: string) => request.get(`${API.UserPage_URL}/select?searchKey=${searchKey}`), //用户下拉列表
}
